package com.dingding.web.validate;

import java.io.IOException;

import org.apache.log4j.Logger;

import com.dingding.common.core.image.captcha.SCaptcha;
import com.dingding.web.base.action.BaseAction;

/**
 * 
 * @ClassName: ValidateCodeAction 
 * @Description: 获取图片验证码Action
 * @author CHEHAUNBO 
 * @date 2016年9月22日 下午1:05:50
 * @version V2.5.0
 * 
 */
public class ValidateCodeAction extends BaseAction {

	private static final long serialVersionUID = 1L;
	private static final Logger log = Logger.getLogger(ValidateCodeAction.class);

	/**
	 * 
	 * 获取图形验证码
	 * 
	 * @Title: getValidateCode 
	 * @author CHEHAUNBO
	 * 
	 */
	public String validateCode() {

		try {
			SCaptcha captcha = new SCaptcha();
			response.setHeader("Pragma", "no-cache");
			response.setHeader("Cache-Control", "no-cache");
			response.setDateHeader("Expires", 0);
			request.getSession().setAttribute(request.getSession().getId(), captcha.getCode());
			captcha.write(response.getOutputStream());
		} catch (IOException e) {
			log.error("生成图形验证码出现异常！ValidateCodeAction:validateCode()",e);
		}

		return NONE;

	}

}
